package com.ruoyi.logistic.controller;

import com.ruoyi.common.core.domain.R;
import com.ruoyi.logistic.domain.NetworkName;
import com.ruoyi.logistic.domain.PageDate;
import com.ruoyi.logistic.service.INetworkNameService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RequestMapping("/network/name")
@RestController
@Api(tags = "网点财务_网点名称")
public class NetworkNameController {
    @Autowired
    private INetworkNameService networkNameService;

    @ApiOperation("显示网点名称列表")
    @GetMapping("/selectAll")
    public R selectAll(){
        List<NetworkName> networkNames = networkNameService.selectAll();
        if (networkNames == null || networkNames.size() == 0){
            return R.fail("暂无数据");
        }else {
            return R.ok(networkNames);
        }
    }
    @ApiOperation("添加网点名称")
    @PostMapping("/insert")
    public R insert(@RequestBody NetworkName networkName){
        Boolean isAdd = networkNameService.insert(networkName);
        if (isAdd){
            return R.ok("添加成功");
        }else {
            return R.fail("添加失败");
        }
    }
    @ApiOperation("修改网点名称")
    @PostMapping("/update")
    public R update(@RequestBody NetworkName networkName){
        Boolean isUpdate = networkNameService.update(networkName);
        if (isUpdate){
            return R.ok("修改成功");
        }else {
            return R.fail("修改失败");
        }
    }
    @ApiOperation("删除网点名称")
    @PostMapping("/deleteById")
    public R deleteById(Integer id){
        Boolean isDelete = networkNameService.deleteById(id);
        if (isDelete){
            return R.ok("删除成功");
        }else {
            return R.fail("删除失败");
        }
    }
    @ApiOperation("显示承包区")
    @GetMapping("/selectContractArea")
    public R selectContractArea(){
        List<NetworkName> networkNames = networkNameService.selectContractArea();
        if (networkNames == null || networkNames.size() == 0){
            return R.fail("暂无数据");
        }else {
            return R.ok(networkNames);
        }
    }

    @ApiOperation("显示网点下的承包区")
    @GetMapping("/selectByNetworkId")
    public R selectByNetworkId(){
        List<NetworkName> networkNames = networkNameService.selectContractArea();
        if (networkNames == null || networkNames.size() == 0){
            return R.fail("暂无数据");
        }else {
            return R.ok(networkNames);
        }
    }
}
